package geom

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/stretchr/testify/require"
	"testing"
)

func TestColliderContains_Triangles(t *testing.T) {
	p1 := Point{X: 800, Y: 600}
	p2 := Point{X: 894, Y: 733}
	p3 := Point{X: 894.5, Y: 733}

	vs := []ebiten.Vertex{
		{DstX: 800, DstY: 600, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 899.1288, DstY: 694.8861, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 797.87866, DstY: 602.12134, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 894.8861, DstY: 699.1288, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 897.00745, DstY: 697.00745, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 899.1288, DstY: 694.8861, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 900.00745, DstY: 697.00745, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 900.00745, DstY: 697.00745, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 900.00745, DstY: 733.68335, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 894.00745, DstY: 697.00745, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
		{DstX: 894.00745, DstY: 733.68335, SrcX: 1, SrcY: 1, ColorR: 1, ColorG: 1, ColorB: 0, ColorA: 1},
	}
	is := []uint16{0, 1, 2, 1, 3, 2, 4, 5, 6, 7, 8, 9, 8, 10, 9}

	c := MakeTrianglesCollider(vs, is)
	require.True(t, c.Contains(p1))
	require.False(t, c.Contains(p2))
	require.True(t, c.Contains(p3))
	require.False(t, c.Contains(Point{X: 0, Y: 0}))
	require.False(t, c.Contains(Point{X: 799, Y: 599}))
}
